import { getToken, setToken, removeToken } from '@/utils/auth.js'
// , setToken, removeToken
import { login } from '@/api/login.js'
import { defineStore } from 'pinia'

// export
const useStoreLogin = defineStore('userLogin', {
  state: () => {
    return {
      token: getToken()
    }
  },
  getters: {},
  actions: {
    storeLogin(data) {
      login(data)
        .then((res) => {
          setToken(res.data.access_token)
        })
        .catch((err) => {
          console.log(err)
        })
    },
    removeLognToken() {
      removeToken()
    }
  }
})

export { useStoreLogin }
